using System.ComponentModel.DataAnnotations;
using ChatBackend.Models;

namespace ChatBackend.DTOs
{
    public class CreateChatRoomDto
    {
        [Required(ErrorMessage = "聊天室名称是必需的")]
        [StringLength(100, MinimumLength = 1, ErrorMessage = "聊天室名称长度必须在1-100个字符之间")]
        public string Name { get; set; } = string.Empty;

        [StringLength(500, ErrorMessage = "描述长度不能超过500个字符")]
        public string? Description { get; set; }

        [Required(ErrorMessage = "聊天室类型是必需的")]
        public ChatRoomType Type { get; set; }

        public List<int>? MemberIds { get; set; }
    }

    public class ChatRoomDto
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string? Description { get; set; }
        public ChatRoomType Type { get; set; }
        public int CreatedBy { get; set; }
        public DateTime CreatedAt { get; set; }
        public bool IsActive { get; set; }
        public List<UserDto> Members { get; set; } = new();
        public MessageDto? LastMessage { get; set; }
        public int UnreadCount { get; set; }
    }

    public class SendMessageDto
    {
        [Required(ErrorMessage = "聊天室ID是必需的")]
        public int ChatRoomId { get; set; }

        [Required(ErrorMessage = "消息内容是必需的")]
        [StringLength(2000, MinimumLength = 1, ErrorMessage = "消息内容长度必须在1-2000个字符之间")]
        public string Content { get; set; } = string.Empty;

        public MessageType Type { get; set; } = MessageType.Text;
    }

    public class MessageDto
    {
        public int Id { get; set; }
        public int ChatRoomId { get; set; }
        public int SenderId { get; set; }
        public string Content { get; set; } = string.Empty;
        public MessageType Type { get; set; }
        public DateTime CreatedAt { get; set; }
        public bool IsEdited { get; set; }
        public DateTime? EditedAt { get; set; }
        public UserDto? Sender { get; set; }
    }

    public class ChatHistoryDto
    {
        public List<MessageDto> Messages { get; set; } = new();
        public int TotalCount { get; set; }
        public int PageNumber { get; set; }
        public int PageSize { get; set; }
        public bool HasNextPage { get; set; }
    }
}
